import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';

import '../../../routes/app_pages.dart';
import '../../../style/app_colors.dart';
import '../../../style/widget_style.dart';
import '../../../widgets/AppHeader.dart';
import '../controllers/validate_code_controller.dart';

class ForgotValidateCodeView extends GetView<ForgotValidateCodeController> {
  ForgotValidateCodeView({super.key});
  final GlobalKey _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
          child: Stack(
            children: [
              Container(
                child: SvgPicture.asset(
                  "assets/images/header_part_bg.svg",
                  width: Get.width,
                ),
              ),
              AppHeader.obtainHeaderWithoutTitleAndRightPart(),
              Obx(()=>Container(
                padding: EdgeInsets.all(15.w),
                width: Get.width,
                margin: EdgeInsets.only(top: 145.h),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Text(controller.isEmailType.value ? "输入邮箱验证码": "输入手机验证码",style: AppStyleThemeData.BIG_TITLE)
                      ],
                    ),
                    SizedBox(height: 45.h,),
                    Container(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(controller.isEmailType.value ? '已发送验证码到邮箱': '已发送验证码到手机',style: AppStyleThemeData.SECOND_TITLE,),
                          SizedBox(height: 20.h,),
                          Text('${controller.account.value}',style: AppStyleThemeData.SECOND_CONTENT)
                        ],
                      ),
                    ),
                    SizedBox(height: 30.h,),
                    Container(
                      padding: EdgeInsets.only(left: 36.w,right: 36.w),
                      height: 80.h,
                      decoration: BoxDecoration(
                        color: AppColors.hexF5F5F5,
                        borderRadius: BorderRadius.circular(8), // Optional: add border radius
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }
                                    },
                                    focusNode: controller.focusNode1.value,
                                    controller: controller.textEditor1.value,
                                  ),
                                  controller.hiddenUnderLine1.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),
                          SizedBox(width: 24.w,),
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }else{
                                        controller.jumpPreFocus('2');
                                      }
                                    },
                                    focusNode: controller.focusNode2.value,
                                    controller: controller.textEditor2.value,
                                  ),
                                  controller.hiddenUnderLine2.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),
                          SizedBox(width: 24.w,),
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }else{
                                        controller.jumpPreFocus('3');
                                      }
                                    },
                                    focusNode: controller.focusNode3.value,
                                    controller: controller.textEditor3.value,
                                  ),
                                  controller.hiddenUnderLine3.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),
                          SizedBox(width: 24.w,),
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }else{
                                        controller.jumpPreFocus('4');
                                      }
                                    },
                                    focusNode: controller.focusNode4.value,
                                    controller: controller.textEditor4.value,
                                  ),
                                  controller.hiddenUnderLine4.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),
                          SizedBox(width: 24.w,),
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }else{
                                        controller.jumpPreFocus('5');
                                      }
                                    },
                                    focusNode: controller.focusNode5.value,
                                    controller: controller.textEditor5.value,
                                  ),
                                  controller.hiddenUnderLine5.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),
                          SizedBox(width: 24.w,),
                          Expanded(child:  Container(
                              child: Column(
                                children: [
                                  TextFormField(
                                    inputFormatters: [
                                      LengthLimitingTextInputFormatter(1),
                                    ],
                                    keyboardType: TextInputType.number,
                                    decoration: InputDecoration(
                                        focusedBorder: InputBorder.none,
                                        contentPadding: EdgeInsets.only(top: 25.h)
                                    ),
                                    onChanged: (v) {
                                      if(v != '') {
                                        controller.changeFocus();
                                      }else{
                                        controller.jumpPreFocus('6');
                                      }
                                    },
                                    focusNode: controller.focusNode6.value,
                                    controller: controller.textEditor6.value,
                                  ),
                                  controller.hiddenUnderLine6.value ? SizedBox() : Divider(
                                    height: 2.0, // 可以调整高度来改变横线的粗细
                                    color: Colors.grey, // 可以调整颜色
                                  ),
                                ],
                              ),
                              width: 90.w,
                              height: 90.h
                          ),flex: 1,),

                        ],
                      ),
                    ),
                    SizedBox(height: 10.h,),
                    Visibility(
                      visible: (!controller.isCheck.value) &&(!controller.showTimeText.value),
                      child: RichText(
                        text: TextSpan(
                            children: [
                              TextSpan(text: '没有收到验证码? ', style: AppStyleThemeData.normal_gray),
                              TextSpan(text: '重新发送',style: AppStyleThemeData.linkStyle,recognizer: TapGestureRecognizer()..onTap=controller.reTryValidateCode),
                            ]
                        ),
                      ),
                    ),
                    Visibility(
                      visible: (!controller.isCheck.value) &&(controller.showTimeText.value),
                      child: RichText(
                        text: TextSpan(
                            children: [
                              TextSpan(text:'重新发送 ${controller.timeCount.value}',style: AppStyleThemeData.normal_gray)
                            ]
                        ),
                      ),
                    ),

                    SizedBox(height: 50.h),
                    /*Text('验证码错误或失效.', style: AppStyleThemeData.normal_red),
                    SizedBox(height: 40.h,),*/
                    Visibility(
                      visible: controller.isCheck.value,
                      child: Container(
                        width: 594.w,
                        child: ElevatedButton(
                            onPressed: () {
                              if(controller.isCheckSuccess.value){
                                // Get.toNamed(Routes.LOGIN);
                              }else{
                                if(!controller.showTimeText.value){
                                  controller.reTryValidateCode();
                                }

                              }

                            },
                            child:  Text(controller.isCheckSuccess.value?'返回登录':
                            controller.showTimeText.value?'重新获取 (${controller.timeCount.value})':
                            '重新获取')
                        ),
                      ),
                    )

                  ],
                ),
              ))
            ],
          ),
        )
    );
  }
}
